﻿
    @*<script src="~/Scripts/jquery-1.8.0.min.js"></script>
    <script src="~/Scripts/jquery-1.8.0.js"></script>
    <script src="~/Scripts/jquery.form.js"></script>*@
  @*<script src="~/Scripts/jquery.jsonp.js"></script>*@
  <script src="~/Scripts/jquery.min.js"></script>
  
    @*<script type="text/javascript">
            $(function () {
                $("#btn").click(function () {
                    alert("ddd");
                    var _rootUrl = "@Url.Content("~")";
                    $("#form2").ajaxSubmit({
                        url: _rootUrl + 'Home/Uploadfile',
                        type: 'post',
                        success: function (data) {
                            data = data.replace('<PRE>', '').replace('</PRE>', '');
                            $('#divimg').append('<img src="' + data + '" width="200px"  height="200px" />');
                            var file = $('#btnfile');
                            file.after(file.clone().val(''));
                            file.remove();
                        }
                    });
                });
            });
        </script>*@

   @*<script type="text/javascript">
        $(document).ready(function () {

            $("#btn").click(function () {
                alert("123");
                var _rootUrl = "@Url.Content("~")";
                $("#form").ajaxSubmit({
                    url: _rootUrl + 'Home/Uploadfile',
                    type: 'post',

                    success: function (data) {
                        data = data.replace('<PRE>', '').replace('</PRE>', '');
                        $('#divimg').append('<img src="' + data + '" width="200px"  height="200px" />');
                        var file = $('#btnfile');
                        file.after(file.clone().val(''));
                        file.remove();
                    }
                })
            })

        })
 </script>*@

@*<form id="form" method="post">
    <input type="file" id="btnfile" name="btnfile" value="提交" />
    <input type="button" id="btn" value="上传" />
</form>*@

@*使用query+又拍云服务端上传图片*@
@*<form id="form" method="post">
    <input type="file" id="btnfile" name="btnfile" value="提交" multiple="multiple"  />
    <input type="button" id="btn" value="上传" />
</form>

<script type="text/javascript">
   $(function () {
       $("#btn").click(function () {
          
            var _rootUrl = "@Url.Content("~")";
            var strFile = $('input[name="btnfile"]').prop('files');//获取到文件列表
            var formData = new FormData();
            for (var i = 0; i < strFile.length; i++) {
                formData.append("myfile", strFile[i]);
            }
            $.ajax({
                url: _rootUrl + 'Home/Uploadfile',
                type: "POST",
                data: formData,
                contentType: false,
                processData: false,
                success: function (data) {
                    data = data.replace('<PRE>', '').replace('</PRE>', '');
                    $('#divimg').append('<img src="' + data + '" width="200px"  height="200px" />');
                    var file = $('#btnfile');
                    file.after(file.clone().val(''));
                    file.remove();
                }
            })
        })
    })
</script>*@

@*-----------------------------------*@


@*<form class="form-horizontal" role="form" method="post"
      enctype="multipart/form-data">

    <div class="form-group">
        <label for="url" class="col-sm-2 control-label"><s>*</s>图片选择:</label>
        <div class="col-sm-7">
            <input type="file" name="file" id="file_upload" value=""
                   class="form-control" placeholder="图片地址">
        </div>
    </div>

    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-7">

            <a id="btnAjax" class="btn btn-info col-md-5 col-lg-offset-1">图片上传</a>
        </div>
        
    </div>
</form>*@

@*------------待调试---------------*@
<form id="form" method="post">
    <input type="file" id="btnfile" name="btnfile" value="提交" />
    <input type="button" id="btn" value="上传" />
</form>

<script type="text/javascript">
    $(document).ready(function () {
        $("#btn").click(function () {
            var url = "http://v0.api.upyun.com/caigoupic-1";
            var formData = new FormData();
            formData.append("authorization","@ViewData["authorization"]");
            //formData.append("file", $("#btnfile")[0].files[0]);

            //formData.append("file", $('input[name="btnfile"]').prop('files'));

            formData.append("policy","@ViewData["Policy"]");
           
            //for (var i = 0; i < file.length; i++) {
            //formData.append("file", $('input[name="btnfile"]').prop('files'));
            formData.append("file", $("#btnfile")[0].files[0]);
            //}
            $.ajax({
                url:url,
                type: "POST",
                data: formData,
                contentType: false,
                processData: false,
                success: function (data) {
                    alert("上传成功");
                }
            })
        })
    })
</script>